package com.gp8.tier3;

import java.io.Serializable;

//Pour RMI
import java.rmi.Remote;
import java.rmi.RemoteException;


//Pour REST
import javax.xml.bind.annotation.XmlRootElement;

import java.util.Date;

@XmlRootElement(name = "Piafferie")
public class Piafferie implements Serializable, Remote, Comparable<Piafferie> {

	private static final long serialVersionUID = 1L;
	private Integer id;
	private Piaffeur auteur;
	private String message;
	private Date date;
	
	
	public Piafferie(Integer pID, Piaffeur pAuteur, String pMessage) throws RemoteException {
		super();
		this.setID(pID);
		this.setAuteur(pAuteur);
		this.setMessage(pMessage);
		this.setDate(new Date());
	}
	
	public Integer getID() throws RemoteException {
		return id;
	}
	
	private void setID(Integer pID) throws RemoteException {
		this.id = pID;
	}
	
	public Piaffeur getAuteur() throws RemoteException {
		return auteur;
	}
	
	public void setAuteur(Piaffeur pAuteur) throws RemoteException {
		this.auteur = pAuteur;
	}
	
	public String getMessage() throws RemoteException {
		return message;
	}
	
	public void setMessage(String pMessage) throws RemoteException {
		this.message = pMessage;
	}
	
	public Date getDate() throws RemoteException {
		return date;
	}
	
	public void setDate(Date pDdate) throws RemoteException {
		this.date = pDdate;
	}
	
	@Override
    public boolean equals(Object object)
    {
        boolean same = false;

        if (object != null && object instanceof Piaffeur)
        {
        	try {
				same = (this.id == ((Piafferie)object).getID());
			} catch (RemoteException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
        }

        return same;
    }
	
	@Override
    public int hashCode() {
        int hash = 1;
        hash = hash + id.hashCode();
        return hash;
    }
	
	public int compareTo(Piafferie piafferie) {
		int result = 0;
		
		try {
			if (this.getDate().compareTo(piafferie.getDate()) > 0) {
				result = 1;
			} else if (this.getDate().compareTo(piafferie.getDate()) > 0) {
				result = -1;
			} else if (this.getDate().compareTo(piafferie.getDate()) == 0) {
				result = 0;
			}
		} catch (RemoteException e) {
			e.printStackTrace();
		}
		
		return result;
	}
	
}
